$(function(){
	
	dataInit();
});

function dataInit() {
	//可供报修的数据
	$.ajax({
		url: "../contract/queryLoginCustomer.action",
		type: "post",
		success: function(data) {
			var canBillDeviceHtml = '';
			//style="position: absolute; left: 0%; top: 0px;"
			//style="position: absolute; left: 24.9431%; top: 0px;"
			//style="position: absolute; left: 49.9621%; top: 0px;"
			//style="position: absolute; left: 74.981%; top: 0px;"
			//style="position: absolute; left: 0%; top: 497px;"
			//style="position: absolute; left: 74.981%; top: 497px;"
			//style="position: absolute; left: 24.9431%; top: 498px;"
			//style="position: absolute; left: 49.9621%; top: 498px;"
			//position: absolute; left: 0%; top: 995px;"
			var maxTop = 0;
			$(data).each(function(index, obj){
				obj.device = getDeviceById(obj.deviceId);
				var top = 500 * parseInt(index/3);
//				var left = 24.9431*(index%4);
				var left = 33.3333*(index%3);
				if (top > maxTop) {
					maxTop = top;
				}
				canBillDeviceHtml += '<div class="masonry-grid-item col-sm-6 col-lg-4 g-mb-30" style="position: absolute; left: '+left+'%; top: '+top+'px">'
								+	    '<article class="u-block-hover">'
								+	      '<div class="g-bg-cover g-bg-white-gradient-opacity-v1--after">'
								+	        '<img class="d-flex align-items-end u-block-hover__main--mover-down" src="'+obj.device.deviceImageUrl+'"  style="max-width:100%;"  alt="Image Description">'
								+	      '</div>'
								+	      '<div class="u-block-hover__additional--partially-slide-up text-center g-z-index-1 mt-auto">'
								+	        '<div class="u-block-hover__visible g-pa-25">'
								+	          '<span class="d-block g-color-white-opacity-0_7 g-font-weight-600 g-font-size-12 mb-2"></span>'
								+	          '<h2 class="h4 g-color-white g-font-weight-600 mb-3">'
								+	            '<a class="u-link-v5 g-color-white g-color-primary--hover g-cursor-pointer" href="../bill/deviceDetail.action?deviceId='+obj.deviceId+'&contractId='+obj.id+'" target="_black">'+obj.device.deviceName+'</a>'
								+	          '</h2>'
								+	          '<h4 class="d-inline-block g-color-white-opacity-0_7 g-font-size-11 mb-0">'
								+	            '<a class="g-color-white-opacity-0_7 text-uppercase" href="#">'+moment(obj.startTime).format('YYYY-MM-DD')+'</a>'
								+	          '</h4>'
								+	          '<span class="g-color-white-opacity-0_7 g-pos-rel g-top-2 mx-2">&sim;</span>'
								+	          '<span class="g-color-white-opacity-0_7 g-font-size-10 text-uppercase">'+moment(obj.endTime).format('YYYY-MM-DD')+'</span>'
								+	        '</div>'
								+	        '<a class="d-inline-block g-brd-bottom g-brd-white g-color-white g-font-weight-600 g-font-size-12 text-uppercase g-text-underline--none--hover g-mb-30" href="../bill/form.action?contractId='+obj.id+'" target="_black">我要报修</a>'
								+	      '</div>'
								+	    '</article>'
								+	  '</div>';
			});
			
			$("#billDeviceArea").after(canBillDeviceHtml);
			var styleLimit = 'position: relative; height: '+(maxTop+500)+'px;'
			$("#billDeviceArea").parent().attr("style", styleLimit);
		},
		error: function() {
			toastr.error("获取可供报修设备信息发生错误，请稍后尝试");
		}
	});
  
}


